﻿Imports System.Data
Imports Mysoft.Map.Data
Partial Public Class SaleModiApply_ChgCstName_Edit
    Inherits Mysoft.Map.Application.Security.AppPage

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Dim MyBizParamMNG As New Mysoft.PubProject.Business.BizParamMNG

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码

        Dim strMode, strSaleGUID As String
        strMode = Request.QueryString("mode")
        strSaleGUID = Request.QueryString("SaleGUID")

        '当天时间
        Dim strToday As String
        strToday = Format(Today(), "yyyy-MM-dd")
        txtToday.Value = strToday

        '当前操作员
        Dim strUserName As String
        strUserName = Session("UserName")
        txtUserName.Value = strUserName

        '新增模式

        '取出当前销售单取出对应的客户名称、客户GUID、房间、房间GUID、项目GUID、单位GUID、销售单类型,交易GUID
        Dim dtTrade As DataTable
        Dim strSQL As String
        Dim strCstName, strCstAllGUID, strRoominfo, strRoomGUID, strProjGUID, strBUGUID, strSaletype, strTradeGUID As String

        strSQL = "SELECT top 1 CstName,CstAllGUID,Roominfo,RoomGUID,ProjGUID,BUGUID,(case when Saletype='合同' then '合同' else '定单' end)  as SaleType,TradeGUID " & _
                 "FROM vs_trade  " & _
                 "WHERE SaleGUID='" & strSaleGUID & "'"
        dtTrade = MyDB.GetDataTable(strSQL)

        If dtTrade.Rows.Count() > 0 Then
            strTradeGUID = dtTrade.Rows(0).Item("TradeGUID").ToString()
            strCstName = dtTrade.Rows(0).Item("CstName").ToString()
            strCstAllGUID = dtTrade.Rows(0).Item("CstAllGUID").ToString()
            strRoominfo = dtTrade.Rows(0).Item("Roominfo").ToString()
            strRoomGUID = dtTrade.Rows(0).Item("RoomGUID").ToString()
            strProjGUID = dtTrade.Rows(0).Item("ProjGUID").ToString()
            strBUGUID = dtTrade.Rows(0).Item("BUGUID").ToString()
            strSaletype = dtTrade.Rows(0).Item("Saletype").ToString()
        End If

        '取出当前交易对应的已交款金额
        Dim strPay As String
        If strTradeGUID <> "" Then
            strSQL = "SELECT sum(BeforeRmbYe) as Pay FROM s_getin WHERE SaleGUID='" & strTradeGUID & "' and (status<>'作废' or status is null)"
            strPay = MyDB.GetDataItemDecimal(strSQL).ToString()
        Else
            strPay = "0"
        End If

        Dim strApplyTypeOption As String = "增减权益人"
       
        If strMode = "1" Then
            '初始化页面
            appForm.DefaultValueXml = "<xml>" & _
                                        "<BUGUID defaultvalue='" & strBUGUID & "'/>" & _
                                        "<ProjGUID defaultvalue='" & strProjGUID & "'/>" & _
                                             "<appForm_TradeGUID defaultvalue='" & strTradeGUID & "'/>" & _
                                        "<SaleGUID defaultvalue='" & strSaleGUID & "'  defaulttext='详情'/>" & _
                                        "<SaleType defaultvalue='" & strSaletype & "'/>" & _
                                        "<RoomGUID defaultvalue='" & strRoomGUID & "'/>" & _
                                        "<CstName defaultvalue='" & strCstName & "'/>" & _
                                        "<CstGUID defaultvalue='" & strCstAllGUID & "'/>" & _
                                        "<CstGUID1 defaultvalue='" & strCstAllGUID & "' defaulttext='" & strCstName & "'/>" & _
                                        "<RoomGUID1 defaultvalue='" & strRoomGUID & "' defaulttext='" & strRoominfo & "'/>" & _
                                        "<Pay defaultvalue='" & strPay & "'/>" & _
                                         "<ApproveState defaultvalue='待审批'/>" & _
                                        "<ApplyBy defaultvalue='" & strUserName & "'/>" & _
                                        "<ApplyDate defaultvalue='" & strToday & "'/>" & _
                                        "<ApplyType defaultvalue='" & strApplyTypeOption & "'/>" & _
                                        "</xml>"

      
        End If

        '增减权益人是否可用，1可用、0不可用
        Dim strEnableZjqyrSh As String = MyBizParamMNG.GetBizParamConfig("s_EnableZjqyrSh", strProjGUID)    '启用增减权益人审批 ( "0"：不启用；"1"：启用)
        strEnableZjqyrSh = IIf(strEnableZjqyrSh = "", "1", strEnableZjqyrSh)

        txtBgShConfig.Text = strEnableZjqyrSh
    End Sub

    Protected Overrides Sub ConfigureForm()
        appForm.Execute()
    End Sub

End Class
